package fr.miage.course7.app.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.HashMap;
import java.util.TreeSet;

import fr.miage.course7.app.model.Participant;
import fr.miage.course7.app.model.Transmission;

public class ButtonListener implements ActionListener {
	
	Fenetre mainFrame;
	private HashMap<Integer, Participant> lesParticipants;
    private TreeSet<Transmission> lesTransmissions;
	
	public ButtonListener(final Fenetre frame) {
        mainFrame = frame;
    }
	
	public void actionPerformed(ActionEvent evt) {
        mainFrame.getListeDate().removeAll();
		lesParticipants = mainFrame.getControl().getCourse().getParticipants();
        if (!lesParticipants.isEmpty()){
            lesTransmissions = lesParticipants.get(1).getTransmissions();
            for (Transmission transmission : lesTransmissions){
            	mainFrame.getListeDate().add(transmission.getDate().get(Calendar.DATE) + "/" + ((transmission.getDate().get(Calendar.MONTH) != 0)?transmission.getDate().get(Calendar.MONTH):"12") + "/" + transmission.getDate().get(Calendar.YEAR));
            }
        }
        mainFrame.getListeDate().select(mainFrame.getListeDate().getItemCount()-1);
        mainFrame.rafraichir();
	}

}
